package com.ms.teapuesto.jsf;

import com.ms.jsf.JsfBeanBase;
import com.ms.seguridad.support.ViewInfoMgr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 */
@ManagedBean
@Scope("session")
@Component
public class MenuBean  extends JsfBeanBase {


    @Autowired
    ViewInfoMgr viewInfoMgr;

    @PostConstruct
    public void init(){
        System.out.println("xxx");
    }

    public void pageAction(ActionEvent event) throws IOException, ServletException {
        String page = (String) event.getComponent().getAttributes().get("page");
        HttpServletRequest req = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String contextPath = req.getContextPath();
        viewInfoMgr.cleanSession();
        FacesContext.getCurrentInstance().getExternalContext().redirect(contextPath+page);
    }


}
